package accueil.pack;

import chemin.pack.R;
import chemin.pack.R.layout;
import chemins.pack.*;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.util.Log;
import android.view.*;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import communication.AndroidConnection;
import communication.IncomingHandler;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Menu extends Activity {
    AndroidConnection conn;
    int credit;
    int creditInitial;
    LinearLayout.LayoutParams jaugeCreditD= new LinearLayout.LayoutParams(0,LayoutParams.MATCH_PARENT,0);
    LinearLayout.LayoutParams jaugeCreditG= new LinearLayout.LayoutParams(0,LayoutParams.MATCH_PARENT,0);
    View view;
    int distanceParcourueTotale = 0;
    String assistanceType;
    
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            exitActivity(view);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    
    
    @Override
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);

	        /* Set full screen view*/
	        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
	                                         WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        requestWindowFeature(Window.FEATURE_NO_TITLE);

                                
                Bundle extras=getIntent().getExtras();
                    
                credit =extras.getInt("credit");
                this.credit = credit;
                
                assistanceType =extras.getString("assistanceType");
                this.assistanceType = assistanceType;

                
                creditInitial =extras.getInt("creditInitial");
                this.creditInitial = creditInitial;
                
                distanceParcourueTotale = extras.getInt("distanceParcourueTotale");
                this.distanceParcourueTotale = distanceParcourueTotale;

                
	        setContentView(R.layout.menu_interface);
                
                if(creditInitial == -1)
                {
                    findViewById(R.id.menuJaugeBase).setVisibility(View.GONE);                            
                }

                
                initialisationText();
                evolutionCredit();
                
               if(credit <= 0)
                  { 
                     exitActivity(view); 
                  }
                

	    }
	 

	   public void versMonChemin(View v)
	    {

	         Intent intent2 = new Intent(Menu.this, CheminActivity.class);
                 intent2.putExtra("typeDeChemin","monChemin");
                 intent2.putExtra("creditInitial",creditInitial);
                 intent2.putExtra("credit",credit);
                 intent2.putExtra("distanceParcourueTotale",distanceParcourueTotale);
                 intent2.putExtra("assistanceType",assistanceType);
                 
                 finish();
	         startActivity(intent2);
  
	    }
	   
	   public void versCheminTDF(View v)
	    {
	    
	         Intent intent2 = new Intent(Menu.this, SousMenu.class);                 
                 intent2.putExtra("creditInitial",creditInitial);
                 intent2.putExtra("credit",credit);
                 intent2.putExtra("distanceParcourueTotale",distanceParcourueTotale);
                 intent2.putExtra("assistanceType",assistanceType);
                 
                 finish();
	         startActivity(intent2);
 
	    }
	   
	    public void exitActivity(View v)
	    {
                Intent intent2 = new Intent(Menu.this, Login.class);
                startActivity(intent2);
	        finish();

	    }
            
            public void initialisationText()
            {
                Typeface policeAltermove = Typeface.createFromAsset(getAssets(), "eurosti.ttf");
                
                ((TextView) findViewById(R.id.menuTitre1TextView)).setTypeface(policeAltermove);
                ((TextView) findViewById(R.id.menuTitre1TextView)).setTextSize(35);
                
                ((TextView) findViewById(R.id.menuTitre2TextView)).setTypeface(policeAltermove);
                ((TextView) findViewById(R.id.menuTitre2TextView)).setTextSize(35);
	 
            }
            
             public void evolutionCredit()
            {
                    if(credit == 0)
                    { 
                        exitActivity(view); 
                    }
                    jaugeCreditD.weight = (credit);
                    findViewById(R.id.menuCreditJaugeDroite).setLayoutParams(jaugeCreditD);

                    jaugeCreditG.weight = (creditInitial - credit);
                    findViewById(R.id.menuCreditJaugeGauche).setLayoutParams(jaugeCreditG);

                    ((TextView) findViewById(R.id.menuDistanceRestanteTextView)).setText(Integer.toString(credit)+" m");
            }
}